﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Coot
{
    public class FBFriendList : List<FBFriend>
    {
        public FBFriendList()
        {
        }

        public FBFriendList(XmlNodeList friendsXML)
        {
            foreach (XmlNode node in friendsXML)
            {
                long fid = long.Parse(getXmlValue(node.OuterXml, "id"));
                string fname = getXmlValue(node.OuterXml, "name");

                AddFBFriend(fid, fname);
            }
        }

        public void AddFBFriend(long friendUid, string friendName)
        {
            Add(new FBFriend(friendUid, friendName));
        }

        private string getXmlValue(string xml, string key)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(xml);
            XmlNodeList nodes = xDoc.GetElementsByTagName(key);
            return nodes[0].InnerText;
        }
    }
}
